package com.ai.api.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // 插入时自动填充 createTime
        this.strictInsertFill(metaObject,  "createTime", LocalDateTime.class,  LocalDateTime.now());
        // 可选：同时填充 updateTime（根据需求）
        this.strictInsertFill(metaObject,  "updateTime", LocalDateTime.class,  LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 更新时自动填充 updateTime
        this.strictUpdateFill(metaObject,  "updateTime", Date.class,  new Date());
    }
}
